package com.googlecode.alogwe.sprockit.unused;

import java.util.ArrayList;

public class HistoryList {

	private int					pos		= -1;
	private ArrayList<String>	list;
	private int					maxSize	= 0;

	public HistoryList() {
		this(50); // default maxSize;
	}

	public HistoryList(int maxHistorySize) {
		this.maxSize = maxHistorySize;
		list = new ArrayList<String>();
		resetCaret();
	}

	public void add(String input) {
		if (list.size() == this.maxSize) {
			list.remove(0);
		}
		list.add(input);
		resetCaret();
	}

	public String getPreviousEntry() {
		String entry = "";
		if (this.pos > 0) {
			entry = list.get(--pos);
		} else if (!list.isEmpty() && this.pos == 0) {
			entry = list.get(0);
		}
		return entry;
	}

	public String getNextEntry() {
		String entry = "";
		if (this.pos + 1 < list.size()) {
			entry = list.get(++pos);
		}
		return entry;
	}

	public void resetCaret() {
		this.pos = (list.size());
	}

}
